#include <QCoreApplication>
#include <QDebug>

#include "duktape/duktapemanager.h"
#include "mytest.h"
#include "mytest2.h"

enum class Color { Red, Green, Blue };

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    MyTest m_MyTest("时间");

    DuktapeManager pDuktapeManager;
    if(pDuktapeManager.initDukTape())
    {
        pDuktapeManager.registerClassToDukTape<MyTest>();
        pDuktapeManager.registerClassToDukTape<MyTest2>();
        pDuktapeManager.registerClassToDukTape<MyStructTest>();
        pDuktapeManager.registerObjectToDukTape(&m_MyTest,"haha");

        pDuktapeManager.registerEnumToDukTape<Color>("Color", {
            {"Red", Color::Red},
            {"Green", Color::Green},
            {"Blue", Color::Blue}
        });

        pDuktapeManager.runScript("function greet(name) {\n"
                                  "name.print();\n"
                                  "    return 'Hello, ' + name.getName() + '!';\n"
                                  "}\n"
                                  "var test1 = new MyTest(\"mytest1\");\n"
                                  "test1.print();\n"
                                  "var test2 = new MyTest2(\"mytest2\");\n"
                                  "test2.print();\n"
                                  "test2.print2(test2.getName());\n"
                                  "test2.print2(Color.Red+\"+\"+Color.Green+\"+\"+Color.Blue);\n"
                                  "var test3 = new MyStructTest(1000,\"MyStructTest\");\n"
                                  "test2.print2(test3.value+\" \"+test3.name);\n"
                                  "haha.print();\n");

        qDebug()<<pDuktapeManager.execute_function_callback("greet",&m_MyTest).c_str();
    }

    return a.exec();
}
